function Rect(options) {
  this.x = options.location.x;
  this.y = options.location.y;
  this.w = options.width;
  this.h = options.height;
  // 计算中心点坐标（x + w/2, y + h/2）
  this.cx = this.x + (this.w/2)
  this.cy = this.y + (this.h/2)
  this.borderColor = options.border.color;
  this.background = options.background;
  this.lineWidth = options.border.width;
  this.texts = options.texts;
}

Rect.prototype.draw = function (ctx) {
  ctx.save()
  ctx.beginPath()
  ctx.lineWidth = this.lineWidth
  ctx.strokeStyle = this.borderColor
  ctx.fillStyle = this.background.color
  ctx.font = '14px "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif';
  ctx.rect(this.x, this.y, this.w, this.h)
  ctx.fill()
  ctx.stroke()
  ctx.closePath()
  // 写文字
  for (let i = 0; i < this.texts.length; i++) {
    let text = this.texts[i]
    ctx.beginPath();
    ctx.fillStyle = text.color
    ctx.fillText(text.content, this.cx - 6 * text.content.length, this.cy - (5 * (this.texts.length - 1)) + (20 * i))
    ctx.closePath()
  }
  ctx.restore()
}
